#!/bin/bash
# build.sh -- builds JAR and XPI files for mozilla extensions
#   by Nickolay Ponomarev <asqueella@gmail.com>
#   (original version based on Nathan Yergler's build script)
# Most recent version is at <http://kb.mozillazine.org/Bash_build_script>

# This script assumes the following directory structure:
# ./
#   chrome.manifest (optional - for newer extensions)
#   install.rdf
#
#   content/    |
#   locale/     |
#   skin/       |
#
#   defaults/   |
#   components/ |
#   ...         |
#
# It uses a temporary directory ./build when building; don't use that!
# Script's output is:
# $APP_NAME.xpi
#
#
# default configuration file is ./config_build.sh, unless another file is
# specified in command-line. Available config variables:
APP_NAME=          # short-name, xpi files name. Must be lowercase with no spaces
BEFORE_BUILD=      # run this before building       (bash command)
AFTER_BUILD=       # ...and this after the build    (bash command)

if [ -z $1 ]; then
  . ./config_build.sh
else
  . $1
fi

if [ -z $APP_NAME ]; then
  echo "You need to create build config file first!"
  echo "Read comments at the beginning of this script for more info."
  exit;
fi

$BEFORE_BUILD

echo "Generating $APP_NAME.xpi..."
zip -0 -r $APP_NAME.xpi `cat files`

echo "Done!"

$AFTER_BUILD

